package top.zsyle.org.dto;

import lombok.Data;
import org.springframework.beans.BeanUtils;
import top.zsyle.org.domain.Employee;
import top.zsyle.org.domain.Shop;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.Date;

@Data
public class ShopSettlementDto {
    //NotNull 基本数据类型的包装类，eg:Integer
    //NotEmpty 判断集和是否为空
    //NotBlank 判断字符串
    @NotBlank(message = "店铺名不能为空！")
    private String name;
    @NotBlank(message = "店铺电话不能为空！")
    private String tel;
    @NotBlank(message = "店铺地址不能为空！")
    private String address;

    private String logo;

    @Valid
    private EmployeeDto admin;

    public Shop getShop() {
        return  Shop.builder()
                .name(this.getName())
                .tel(this.getTel())
                .address(this.getAddress())
                .logo(this.getLogo())
                .registerTime(new Date())
                .state(0)
                .build();

    }

    public Employee getEmployee(){
        Employee employee = new Employee();
        BeanUtils.copyProperties(admin,employee);
        employee.setState(1);
        return employee;
    }
}
